/**
 * @价格格式化
 * @parms {price}
 */
export const gPrice = (price = "") => {
  let result = [price, ""];
  if (typeof price === "number") {
    price = price.toString();
  }
  const dIndex = price.indexOf(".");
  if (dIndex > -1) {
    result[0] = price.slice(0, dIndex);
    result[1] = price.slice(dIndex);
  }
  return result;
};

/**
 * @判断两个数组是否相同
 * @parms {price}
 */
export const compareArrays = (arr1, arr2) => {
  if (!arr1 || !arr2) return false;
  return arr1.length === arr2.length && arr1.every((item) => arr2.includes(item));
};

// 时间戳转为年月日
export const timestampToDate = (timestamp) => {
  // 创建一个新的Date对象
  let date = new Date(timestamp);
  // 获取年月日
  let year = date.getFullYear();
  let month = ("0" + (date.getMonth() + 1)).slice(-2); // 月份是从0开始的，所以加1，并保证两位数
  let day = ("0" + date.getDate()).slice(-2); // 保证两位数

  // 返回格式化的日期
  return year + "-" + month + "-" + day;
};
